import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [{
  path: '/',
  name: 'Login',
  meta: {
    title: '建行信用卡满200元立减20元'
  },
  // route level code-splitting
  // this generates a separate chunk (about.[hash].js) for this route
  // which is lazy-loaded when the route is visited.
  component: () => import( /* webpackChunkName: "about" */ '../views/Login')
}, {
  path: '/detail',
  name: 'Detail',
  meta: {
    title: '建行信用卡满200元立减20元'
  },
  component: () => import( /* webpackChunkName: "about" */ '../views/Detail')
}, {
  path: '/exchange/:id', // 单个商品详情 页面
  name: 'ExchangeDetail',
  meta: {
    title: '商品详情'
  },
  component: () => import( /* webpackChunkName: "about" */ '../views/Exchange')
}, {
  path: '/payment', // 支付页面 ---- 暂未使用
  name: 'Payment',
  meta: {
    title: '支付'
  },
  component: () => import( /* webpackChunkName: "about" */ '../views/Payment')
}, {
  path: '/use-list/:id', // 加油券使用 状态列表页面
  name: 'UseList',
  meta: {
    title: '个人中心'
  },
  component: () => import( /* webpackChunkName: "about" */ '../views/UseList')
}, {
  path: '/order-detail/:id', // 订单  -- 支付 -- 状态 - 详情页
  name: 'OrderDetail',
  meta: {
    title: '订单详情'
  },
  component: () => import( /* webpackChunkName: "about" */ '../views/OrderDetail')
}, {
  path: '/address-list',
  name: 'AddressList',
  meta: {
    title: '加油站列表'
  },
  component: () => import( /* webpackChunkName: "about" */ '../views/AddressList')
}]

const router = new VueRouter({
  // mode: 'history',
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
  // console.log(to)
  // console.log(from)
  // console.log(next)
  document.title = to.meta.title
  next()
})

export default router